import asyncio
import os
import subprocess

# async def reboot_ocb():
#     while True:
#         try:
#             await asyncio.sleep(60 * 56 * 1)
#             # await asyncio.create_subprocess_exec('systemctl', 'restart', 'rcs-ocb', stdout=subprocess.DEVNULL)
#             await asyncio.create_subprocess_exec('systemctl', 'restart', 'rcs-relays-module', stdout=subprocess.DEVNULL)
#         except Exception:
#             await asyncio.sleep(20)

async def main():
    from services.new_services.technic_page.handler import TechnicPageHandler
    from services.new_services.new_server_integration.handler import NewServerIntegrationHandler
    from services.server_integration.handler import ServerIntegrationHandler

    loop = asyncio.get_event_loop()

    technic_page_handler = TechnicPageHandler()
    new_server_integration_handler = NewServerIntegrationHandler()
    handler = ServerIntegrationHandler(loop)

    loop.create_task(handler.model.alarm_telemetry_loop())
    loop.create_task(handler.model.ping_server_loop())
    loop.create_task(handler.model.fix_reboot_on_invalid_modem_loop())
    loop.create_task(handler.model.send_start_up_signal_to_frontend_loop())
    loop.create_task(handler.model.ping_loop())
    # loop.create_task(reboot_ocb())

    technic_page_handler.receive_messages_in_task(loop)
    new_server_integration_handler.receive_messages_in_task(loop)
    await handler.receive_messages(loop)


if __name__ == '__main__':
    asyncio.new_event_loop()\
        .run_until_complete(main())


